package com.crm.manager.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.crm.common.core.domain.R;
import com.crm.manager.domain.Configuration;
import com.crm.manager.service.ConfigurationService;
import kotlin.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@Slf4j
@RequestMapping("/rule/pool")
public class ConfigurationController {

    @Autowired
    private ConfigurationService configurationService;

    // 根据类型查询配置信息
    @GetMapping("/{type}")
    public R<Configuration> selectByType(@PathVariable Integer type){
        log.info("根据类型查询配置信息,接收到的参数是{}",type);
        return R.ok(configurationService.selectByType(type));
    }

    // 修改配置信息
    @PutMapping
    public R<Configuration> update(@RequestBody Configuration configuration){
        log.info("修改配置信息,接收到的参数是{}",configuration);
        configuration.setUpdateTime(LocalDateTime.now());
        configurationService.update(configuration, Wrappers.<Configuration>lambdaUpdate().eq(Configuration::getType,configuration.getType()));
        return R.ok();
    }
}
